home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
rmtlog1a
/
moderror.bas
< prev
next >
Wrap
BASIC Source File
|
1999-03-21
|
2KB
|
81 lines
Attribute VB_Name = "modErrorHandling"
Option Explicit
' Define your custom errors here. Be sure to use numbers
' greater than 512, to avoid conflicts with OLE error numbers.
Public Const MyObjectError1 = 1000
Public Const MyObjectError2 = 1010
Public Const MyObjectErrorN = 1234
Public Const MyUnhandledError = 9999
Public Const ERR_SOURCE_DISABLED = 10001
Public Const ERR_LOGDEST_DISABLED = 10002
Public Const ERR_CONNECT_FAILED = 10003
Public Const ERR_NO_LOGDEST = 10004
Public Const ERR_NO_SOURCE = 10005
Public Const ERR_FILEOPEN_FAILED = 10006
Public Const ERR_SOURCE_NULL = 10007
Public Const ERR_LOGDEST_NULL = 10008
Public Const ERR_WRITELOG_DISABLED = 10009
'Public Const ERR_ = 10010
'Public Const ERR_ = 10011
'Public Const ERR_ = 10012
'Public Const ERR_ = 10013
'Public Const ERR_ = 10014
'Public Const ERR_ = 10015
'Public Const ERR_ = 10016
'Public Const ERR_ = 10017
'Public Const ERR_ = 10018
'Public Const ERR_ = 10019
'Public Const ERR_ = 10020
Private Function GetErrorTextFromResource(ErrorNum As Long) _
As String
Dim strMsg As String
' this function will retrieve an error description from a resource
' file (.RES). The ErrorNum is the index of the string
' in the resource file. Called by RaiseError
On Error GoTo GetErrorTextFromResourceError
' get the string from a resource file
GetErrorTextFromResource = LoadResString(ErrorNum)
Exit Function
GetErrorTextFromResourceError:
If Err.Number <> 0 Then
GetErrorTextFromResource = "An unknown error has occurred!"
End If
End Function
Public Sub RaiseError(ErrorNumber As Long, Source As String)
Dim strErrorText As String
'there are a number of methods for retrieving the error
'message. The following method uses a resource file to
'retrieve strings indexed by the error number you are
'raising.
strErrorText = GetErrorTextFromResource(ErrorNumber)
'raise an error back to the client
Err.Raise vbObjectError + ErrorNumber, Source, strErrorText
End Sub